'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFYhkhCtrl
 * @description
 * # FinanceFYhkhCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFYhkhCtrl', function($scope, DataService, $rootScope, openApi, Util, $location, $routeParams, FormSubmit) {
        // 底部关联模块类型选框添加
        $scope.sheetObj = {};
        var AccountTypeObj = {};
        AccountTypeObj.sheettitle = "账户类型";
        AccountTypeObj.callback = function(item) {
            $scope.param.opeanAccountType = item.selectTab
            $scope.param.opeanAccountTypeContent = item.selectTabContent
        }
        $scope.sheetObj.AccountTypeObj = AccountTypeObj;
        $scope.showfileType = function() {
            var param = {}
            param.type = "银行账户类型";
            DataService.getData(openApi.getKeyType, param).then(function(data) {
                $scope.sheetObj.AccountTypeObj.tabList = data
                $scope.showSheet("AccountTypeObj")
            })
        };
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };

        $scope.submit = function() {
            if (!$scope.param.opeanAccountType) {
                Util.Toast("请选择账户类型");
                return;
            }

            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.openAccount
            var options = {};
            options.urlParam = urlParam;
            var myDest = {};
            options.param = angular.copy($scope.param, myDest);
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.openAccount
            }
            new FormSubmit(options);
        };

        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });
        };
        // 初始化
        init();
    });
